package dfbz.com.dao;

import dfbz.com.dao.base.BaseDao;
import dfbz.com.model.User;
import dfbz.com.model.UserFocus;
import dfbz.com.utils.JDBCUtil;
import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.RowProcessor;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserFocusDao extends BaseDao<UserFocus> {


    /**
     * 通过当前用户ID和关注的用户ID查询关注表数据
     *
     * @param userId      当前用户ID
     * @param userFocusId 关注的用户ID
     * @return 关注表数据信息
     */
    public UserFocus findFollowData(Integer userId, Integer userFocusId) {
        QueryRunner qr = new QueryRunner(JDBCUtil.getDataSource());
        //开启下划线->驼峰转换所用
        RowProcessor processor = new BasicRowProcessor(new GenerousBeanProcessor());
        UserFocus focus = null;
        try {
            focus = qr.query("select * from user_focus where user_id = ? and user_focus_id = ?", new BeanHandler<>(UserFocus.class, processor), userId, userFocusId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return focus;
    }
}
